Copyright: © Copyright Agilent Technologies, 2000, 2001


About Macros

Macros let you automate a series of manual operations into a single command. 89600-series products use VBScript for their macro programming language. VBScript is a popular scripting language based on a subset of the Visual Basic programming language.

Note

You can run a macro from within another macro, but recursion is not allowed.

What is VBScript?

VBScript is a scripting language that is a subset of the Visual Basic programming language. VBScript programs are easy to create. With 89600-series products, you can create a VBScript program by recording mouse and keyboard operations or you can write (or edit) VBScript programs with the macro editor that comes with 89600-series software.

Using VBScript, you can automate most operations that you perform manually when running the Spectrum Analyzer or Vector Signal Analyzer application. VBScript programs do this by accessing the application's COM API automation objects.

Tip

A complete online reference is available for the COM API. You can access the online reference from the Documentation Roadmap or by clicking the last entry (Shortcut to Programming With the COM API) from the online table of contents. The following link will also take you to the online COM API reference: COM API.

What can macros be used for?

•	One-button applications

•	Automation of repetitive tasks

•	Computation of measurement results that are beyond the scope of the basic 89600

Where can you learn more about VBScript?

•	There are a number of books available for VBScript.

•	Microsoft's VBScript [image] Web page

•	Microsoft Windows Script Host [image] Web page

This web page provides:

−	Access to the Windows Script Host, which allows you to run VBScript programs from the MS-DOS command line.

−	Access to the VBScript debugger

−	Pointers to additional VBScript documentation

•	On the web, just search for "VBScript"

See also

Creating a Macro

Creating a Macro: Example

Importing and Exporting Macros

Useful Macro Operations

Special Functions

VBScript Quick Reference


Creating a Macro

To make a useful macro:

1.	Learn and practice the measurement process on the 89600.

2.	Record your keystrokes while performing the measurement.

3.	Review the VBScript generated by the 89600

4.	Complete the macro by adding commands to:

•	Collect and compute the measurement results.

•	Display and save the results.

•	Prompt the operator for input.

•	Loop and branch the macro.

Note that the analyzer inserts a call to WaitForValidTrace into the macro before recording any commands that require valid trace data (for example, any of the Copy Marker To commands). The WaitForValidTrace accepts an optional number of milliseconds to wait. The default is 10 milliseconds. If you want to specify a different length of time, enter the number of milliseconds after WaitForValidTrace.

Tips

The next topic, Creating a Macro: Example, shows you how to use portions of the above process to create a macro that measures ACPR of an IQ modulated signal.

Useful Macro Operations shows you macros that perform some common operations, such as prompting the operator for input, reading the marker into a variable, reading trace values into an array, and waiting for measurement completion.

See also

About Macros

Special Functions and Constants

Useful Macro Operations

Sample Macros

Importing and Exporting Macros

VBScript Quick Reference


Creating a Macro: Example

This example shows you how to use some of the process in Creating a Macro to create a macro that measures the adjacent channel power ratio (ACPR) of an I/Q modulated signal.

IMPORTANT

This macro was developed using the recorded QPSK.dat signal located in C:\Program files\Agilent\89600 VSA\Help\Signals.

1.	Learn and practice the measurement process

To measure ACPR:

a.	Load the recorded QPSK.dat signal from C:\Program files\Agilent\89600 VSA\Help\Signals.

b.	Tune, span, and range the signal using the steps shown in the online Tutorial, in Using the vector signal analyzer

c.	Turn on averaging.

d.	Set the band power marker to the center and width of the channel. In this case 5 MHz center, 50 KHz channel bandwidth.

e.	Note the channel power/band power reading

f.	Move the band power marker to the adjacent channel. (50 kHz above or below 5 MHz).

g.	Note the adjacent channel power/band power.

h.	Take the difference between the two readings to compute the ratio.

Practice the measurement steps to prepare to record the macro.

2.	Record your keystrokes while performing the measurement

a.	To start recording, click Utilities > Macros from the main menu.

b.	Select Record from the Macros dialog box. All keystrokes are recorded until you return to this dialog box and select End Record.

c.	Perform the ACPR measurement steps as practiced in step 1.

d.	Click Utilities > Macros from the main menu to return to the Macros dialog box. Select End Record.

3.	Review the VBScript Program

a.	The Macro Editor dialog box shows the recorded keystrokes written in VBScript. Take a moment to associate the lines of code with the measurement steps.

Note

The 89600 keeps track of its band power markers in terms of "left" and "right" locations on the trace.

b.	Delete unnecessary lines of code, such as the initial settings of the band power marker. Just highlight the lines to be removed and press the delete key on your keyboard.

c.	Click OK to save the macro.

The macro is given a default name, which you can change. You can also choose an icon to associate with the macro.

d.	Run the macro (from the Macros dialog box, select the new macro, then click Run).

After you run this example, the display will look like this.

Notice that the macro just executes the two band power measurements in rapid succession. This doesn't leave time for the operator to note the results. The next step reads the two marker measurements into the program.

4.	Complete the macro by adding additional commands

a.	Assign the band power measurement result to a variable by adding the following line after the first band power measurement:

chpower = Display.Traces.ActiveTrace.Marker.bandpowerresult

Upon execution of the macro, the variable chpower will contain the value for the power of the carrier.

b.	Assign the adjacent channel power to a variable by adding the following line after the second band power measurement:

achpower = Display.Traces.ActiveTrace.Marker.bandpowerresult

c.	Display the difference between the channel power and adjacent channel power in a message box by adding the following line at the end of the macro:

VsaMsgbox "ACPR = " & chpower-achpower

The modified macro should look like this.

5.	Run the completed macro

When run, the macro will automatically measure, compute, and display ACPR as shown below.

See also

About Macros

Special Functions and Constants

Useful Macro Operations

Sample Macros

Importing and Exporting Macros

VBScript Quick Reference


Importing and Exporting Macros

Import and export macros by recalling or saving them. For example, suppose you create macros using the Vector Signal Analyzer application. If you want to use the macros with the Spectrum Analyzer application, you must first save them from the Vector Signal Analyzer application, then recall them into the Spectrum Analyzer application. You can save to and recall from any directory.

Another use for saving and recalling macros is if you want to edit the macros using an external VBScript editor. If you do this, you must recall the edited macro back into the analyzer. The analyzer keeps a copy of the original macro. If you do not recall the edited macro, the analyzer uses the original version.

See also

About Macros

Creating a Macro


Running a Macro

To run a macro, follow these steps:

1.	Click Utilities > Macros.

2.	From the Macros list, select the macro you want to run.

3.	Click Run.

If the analyzer encounters an error in the macro, it stops the macro and opens an error dialog box asking if you want to edit the macro. If you click Yes, the macro editor opens with the cursor at the line in which the error occurred.


Stopping a Macro

The Run button in the macros dialog box runs the selected macro. This button becomes a Stop button while the macro is running.

If you click the Stop button, the macro stops and the Stop button again becomes the Run button.

Note

Clicking the Run button always runs the macro starting with the first line of code. If you click the Stop button and then click the Run button, execution begins from the first line of code, not from where the macro stopped.

Where Execution Stops

If a macro is running and you click the Stop button, the macro continues executing until it reaches one of the following special functions:

•	VsaInputBox

•	VsaMsgBox

•	VsaSleep

•	VsaDoEvents

When the macro reaches one of the above special functions, the macro stops and generates a "Macro Stopped" error message.


VBScript Quick Reference

The following statements and functions are standard VBScript functions and are included in this topic for your convenience. These functions are explained in detail in most VBScript books and on Microsoft's VBScript Web page

Tip

There are also some special functions created specifically for 89600-series macros, such as VsaDoEvents and VsaSleep. For details, see Special Functions .

Statements Supported in VBScript

Statement	Description
Call	Invokes a subroutine
Const	Declares a constant value
Dim	Declares variables
Do/Loop	Executes a loop until a condition or while a condition is True
Erase	Reinitializes the contents of a fixed-size array and frees all of the memory allocated to a variable-sized array
For/Next	Executes a loop while iterating a variable
For Each/Next	Executes a loop while iterating through a collection of objects
Function/End Function	Declares a routine that will return a value
If/Then/Else/End If	Conditionally executes one set of statements or another
On Error	Takes the specified action if an error condition arises
Option Explicit	Requires that all variables must be declared before their use
Private	Declares private variables
Public	Declares public variables
Randomize	Initializes the random-number generator
ReDim	Changes the size of an array
Select Case/End Select	Chooses a single condition from a list of possible conditions
Set	Assigns a reference to an object or creates a new object
Sub	Declares a subroutine
While/Wend	Executes a loop while a condition is True
Functions Available in VBScript

Function	Description
Abs	Returns the absolute value of a number
Array	Returns a variant containing an array with the specified values
Asc/AscB/AscW	Returns the ASCII value of a character
Atn	Returns the arctangent of the argument
Chr/ChrB/ChrW	Returns a character for a specific ASCII value
CBool	Converts a value to Boolean
CByte	Converts a value to Byte
CCur	Converts a value to Currency
CDate	Converts a value to Date
CDbl	Converts a value to Double
CInt	Converts a value to Integer
CLng	Converts a value to Long
Cos	Returns the cosine of the argument
CreateObject	Creates a new instance of the specified object
CSng	Converts a value to Single
Date	Returns the current date
DateDiff	Returns the number of intervals between two dates
DateSerial	Converts month, day, and year values to a Date value
DateValue	Returns a date part of a Date value
Exp	Returns the exponential of the argument
Filter	Returns a string array that meets the specified filter criteria
Fix	Returns the integer part of a number (Fix (1.2) = 1 and Fix(-1.2) = -1)
FormatCurrency	Formats a value as currency
FormatDateTime	Formats a value as a date or time
FormatNumber	Formats a number
FormatPercent	Formats a number as a percentage
GetObject	Returns a reference to an automation object
Hex	Returns a string containing the hexadecimal value of a number
InputBox	Unsupported, use VsaInputBox instead.
InStr/InStrB	Returns the starting position of the specified substring
InStrRev	Similar to InStr but starts at the end of the string.
Int	Returns an integer part of a number. (Int (1.2) = 1 and Int (-1.2) = -2)
IsArray	Returns True if the argument is an array
IsDate	Returns True if the argument contains a valid Date value
IsEmpty	Returns True if the argument has not been initialized
IsNull	Returns True if the argument contains no valid data
IsNumeric	Returns True if the argument contains a valid number
IsObject	Returns True if the argument contains an object
Join	Joins together a series of strings (opposite of Split)
LBound	Returns the smallest available subscript for the indicated dimension of an array
LCase	Returns a string that has been converted to lowercase characters
Left/LeftB	Returns the leftmost part of a string or byte array
Len/LenB	Returns the length of a string or byte array
LoadPicture	Loads a picture object
Log	Returns the log of the argument
LTrim	Removes leading spaces from a string
Mid/MidB	Returns a substring from the middle of a string or byte array
MsgBox	Unsupported, use VsaMsgBox instead
Now	Returns the current date and time according to the setting of your computer's system date and time
Oct	Returns a string containing the octal value of a number
Replace	Replaces one substring with another substring the specified number of times
RGB	Returns a color based on values for red, green, and blue
Right/RightB	Returns the rightmost part of a string or byte array
Rnd	Returns the next random number from the random-number generator
Round	Rounds a value to the specified number of decimal places
RTrim	Removes trailing spaces from a string
Sgn	Returns -1 if the argument is negative, 0 if it's zero, +1 if it's positive
Sin	Returns the sine of the argument
Space	Fills a string with the specified number of spaces
Split	Breaks apart a string into multiple strings based on a substring (opposite of Join)
Sqr	Returns the square root of the argument
StrComp	Compares strings
String	Fills a string with a specified character the specified number of times
StrReverse	Reverses the order of the characters in the string
Tan	Returns the tangent of the argument
Time	Returns the current time
TimeSerial	Converts hour, minute, and second values to a Date value
TimeValue	Returns the time part of a Date value
Trim	Removes leading and trailing spaces from a string
TypeName	Returns a string containing the name of the type of variable
Ubound	Returns the largest available subscript for the indicated dimension of an array
UCase	Returns a string that has been converted to uppercase
VarType	Returns an integer containing the type of variable


Special Functions and Constants
About Special Functions and Constants

89600-series macros provide special functions (as shown in the following table) and full support of all COM API constants.

Tip

For a list of COM API constants, see the Constants Table in the COM API online help.

89600-series Special Functions

Function	Description
VsaDoEvents	This function is similar to the Do Events Visual Basic function. Use this function to synchronize events.
VsaInputBox	This function is similar to the InputBox Visual Basic function. It prompts you for input and returns the input as a string.
VsaListBox	This function is similar to the ListBox Visual Basic function. It presents you with a list and returns the selected string as its value.
VsaMsgBox	This function is similar to the MsgBox Visual Basic function. It displays a message and one or more buttons that you can click. It returns an integer indicating which button you clicked.
VsaSleep	This function is similar to the Win32 Sleep function, and allows other threads (e.g. the measurement) to run while running your macro.


VsaDoEvents Function

This function is similar to the Do Events Visual Basic function. It yields execution so that the analyzer can process other events.

Syntax: VsaDoEvents( )

Remarks

VsaDoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue.

CAUTION

Any time you temporarily yield the processor within an event procedure, make sure the procedure is not executed again from a different part of your code before the first call returns; this could cause unpredictable results. In addition, do not use VsaDoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.

Example

wait for measdone, but don't bother it too often

measdone is set when either a single sweep measurement finishes

  or an averaged measurement finishes (and pauses)

dim vTime

dim bMeasDone

vTime = Now

Do

   VsaSleep 100

   VsaDoEvents

   bMeasDone = (Measurement.Status.Value And vsaStatusBitMeasDone) <>0

exit after 5 seconds

Loop Until bMeasDone Or DateDiff("s", vTime, Now) > 5


VsaInputBox Function

Displays a prompt in a dialog box, waits for you to input text or click a button, and returns a String containing the contents of the text box.

Syntax: VsaInputBox(prompt[, title] [, default] [, xpos] [, ypos]])

The VsaInputBox function syntax has these named arguments:

Part	Description
prompt	Required. String expression displayed as the message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return-linefeed character combination (Chr(13) & Chr(10)) between each line, or the constant vbCrLf.
title	Optional. String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar.
default	Optional. String expression displayed in the text box as the default response if no other input is provided. If you omit default, the text box is displayed empty.
xpos	Optional. Numeric expression that specifies, in twips, the horizontal distance of the left edge of the dialog box from the left edge of the screen. If xpos is omitted, the dialog box is horizontally centered.
ypos	Optional. Numeric expression that specifies, in twips, the vertical distance of the upper edge of the dialog box from the top of the screen. If ypos is omitted, the dialog box is vertically positioned approximately one-third of the way down the screen.
Remarks

If you click OK or press ENTER, the VsaInputBox function returns whatever is in the text box. If you click Cancel, the function returns a zero-length string ("").

Note

To specify more than the first named argument, you must use VsaInputBox in an expression. To omit some positional arguments, you must include the corresponding comma delimiter.

Example

'Get filename from user. The variable response will contain their input.

dim response

response=VsaInputBox("Enter filename…","Filename")


VSAListBox Function

Presents you with a list of choices in the form of a combobox, and returns the selection to the calling macro.

Syntax: VsaListBox(title, listItems[, defaultItem][, sorted][, xpos][, ypos])

Part	Description
title	Required. The caption that appears in the dialog title bar.
listItems	Required. An array of strings that appear in the combobox. The selected string is returned as the value. If you click Cancel, the empty string is returned.
defaultItem	Optional. The optional default choice.
sorted	Optional. Indicates whether the choices are to be sorted or not.
xpos,  ypos	Optional. The X and Y positions of the dialog box. Default is to center the dialog box on the active window.


VsaMsgBox Function

Displays a message in a dialog box, waits for you to click a button, and returns an Integer indicating which button you clicked.

Syntax: VsaMsgBox(prompt[, buttons] [, title])

The VsaMsgBox function syntax has these named arguments:

Part	Description
prompt	Required. String expression displayed as the message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return - linefeed character combination (Chr(13) & Chr(10)) between each line, or the constant vbCrLf.
buttons	Optional. Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. If omitted, the default value for buttons is 0.
title	Optional. String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar.
Settings

The buttons argument settings are:

Constant	Value	Description
vbOKOnly	0	Display OK button only.
vbOKCancel	1	Display OK and Cancel buttons.
vbAbortRetryIgnore	2	Display Abort, Retry, and Ignore buttons.
vbYesNoCancel	3	Display Yes, No, and Cancel buttons.
vbYesNo	4	Display Yes and No buttons.
vbRetryCancel	5	Display Retry and Cancel buttons.
vbCritical	16	Display Critical Message icon.
vbQuestion	32	Display Warning Query icon.
vbExclamation	48	Display Warning Message icon.
vbInformation	64	Display Information Message icon.
vbDefaultButton1	0	First button is default.
vbDefaultButton2	256	Second button is default.
vbDefaultButton3	512	Third button is default.
vbDefaultButton4	768	Fourth button is default.
vbApplicationModal	0	Application modal; you must respond to the message box before continuing work in the current application.
vbSystemModal	4096	System modal; all applications are suspended until you respond to the message box.
The first group of values (0-5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512) determines which button is the default; and the fourth group (0, 4096) determines the modality of the message box. When adding numbers to create a final value for the buttons argument, use only one number from each group.

Note

These constants are specified by Visual Basic for Applications. As a result, the names can be used anywhere in your code in place of the actual values.

Return Values

Constant	Value	Description
vbOK	1	OK
vbCancel	2	Cancel
vbAbort	3	Abort
vbRetry	4	Retry
vbIgnore	5	Ignore
vbYes	6	Yes
vbNo	7	No
Remarks

If the dialog box displays a Cancel button, pressing the ESC key has the same effect as clicking Cancel.

Note

To specify more than the first named argument, you must use VsaMsgBox in an expression. To omit some positional arguments, you must include the corresponding comma delimiter.

Example

'Display message with OK and Cancel buttons. Clicking

'OK returns 1; clicking Cancel returns 2.

dim response

response=VsaMsgBox("Continue?",vbOKCancel)


VsaSleep Function

The VsaSleep function suspends the execution of the current thread for a specified interval.

Syntax: VsaSleep(time)

Remarks

Specifies the time, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution.

Calling VsaSleep in your macro gives more CPU time to running a measurement.

Example

'Suspend execution for 100 milliseconds.

VsaSleep 100


Macros Dialog Box

Menu Path:  Utilities > Macros

Clicking Utilities, Macros displays the Macros dialog box (see illustration below), which lets you create, edit, save, recall, or delete VBScript macros. The dialog box lists all available macros.

Run	Runs the selected macro. When the macro is running, the name of this button changes to Stop.
Stop	Stops the currently running macro (this button only exists when a macro is running)
New	Displays the Macro Editor dialog box that lets you create a new macro.
Edit	Displays the Macro Editor dialog box. The dialog box shows the code for the selected macro.
Delete	Deletes the selected macro.
Save	Saves a copy of the selected macro to the specified directory.
Recall	Recalls a macro file from the specified directory.
Record	Lets you create a macro by capturing your keystrokes and mouse operations.
See also

About Macros

Creating a Macro

Importing and Exporting Macros


Macro Editor Dialog Box

Menu Path:  Utilities > Macros

The Macro Editor dialog box provides the interface for creating and editing VBScript macros. Features of the dialog box include:

Name	A single-line text box for naming or renaming the macro.
Picture Only	Displays the icon currently associated with the macro. The icons can be placed on toolbars for customizing the application, but it is not necessary to assign one. If none is assigned, the software automatically uses a generic Windows icon.
Text Only	Displays the name of the currently active macro. (See Picture Only above.)
Text & Picture	Displays both the icon associated with the macro and the name of the macro. (See Picture Only above.)
Select	Selects a bitmap file to be associated with the macro as its icon. If you wish to create new icons, start off with a bitmap approximately close to the final size of the icon (64 x 64 pixels); otherwise the lost resolution will make the icon unrecognizable when it is reduced to that size.
Find	Searches for the string in the field to the left of the Find button. The search string is always changed to reflect the current selection in the editor, so you can select the thing that you want to search for. You can also type in a search string, or you can select a previous search string using the drop-down list. Then click Find or <CTRL>-F to move to the next occurrence of the string. The search will wrap at the end of the macro.
Line	Lets you specify a line number in the macro. When you click Go, the cursor moves to that line.
Go	Moves the cursor to the line number you specify in the Line box.
Editing Window	The macro editor always inserts the option Sub Main, Explicit, and End Sub lines when you begin creating a new macro. These are required for all macros, and any legitimate VBScript can be inserted between them.
Buttons	The dialog box features Ok, Cancel, and Check Syntax buttons. Note that Check Syntax only ensures that the macro is correct syntactically, not that it will perform any useful function!
For more information about the Object Model, click Roadmap on the button bar above, and select the COM API documentation.

See also

About Macros

Creating a Macro

Importing and Exporting Macros


Useful Macro Operations

This topic contains a selection of the following frequently used macro operations. You can use copy and paste to copy any of the code in this topic into your macro. Simply select the code and press Ctrl-C to copy the code to the Windows clipboard. Then place your cursor in your macro and press Ctrl-V to paste the code into your macro.

•	Prompting the operator for input

•	Reading the marker into a variable

•	Reading trace values into an array

•	Waiting for measurement completion

•	Looping and branching the macro

Prompting the Operator

An easy way to prompt the operator is with the VsaInputBox function. In the following code, the variable BW receives the operator's response to the prompt.

BW = VsaInputBox("Enter the channel power bandwidth in Hertz.", "Band Power Macro")

The variable BW can then be used to control the band power marker, as in the following lines.

Display.Traces(1).Marker.BandPowerLeft = 1500000000-bw/2
Display.Traces(1).Marker.BandPowerRight = 1500000000+bw/2

Moving and Reading the Marker

The marker may be positioned by a number of commands. The following line positions the marker at the highest peak on the trace using the MoveTo method:

Display.Traces(1).Marker.MoveTo vsaMkrMovePeak

The next line reads the Y-axis value of the marker into a variable:

yMarker=Display.Traces.(1).Marker.Y

Reading Trace Data into an Array Variable

VBScript only provides the "variant" data type. A variant may represent a simple data type (e.g. double) or an array.

dim xData, yData

The trace values may now be read into the array using the Data property and the following lines of code. The data returned is an array of numbers. Data is a read-only property of the Trace object. Reading the Data property returns trace data in the format that is being displayed (e.g. log mag, phase, etc.). The first argument must be vbVariant for macros. The second argument determines whether the data returned is X data (1), Y data (2), or XY data (3). The last argument is typically TRUE and is useful when X-axis scaling is on.

yData = Display.Traces(1).Data(vbVariant, VsaTrcDataY, True)
xData = Display.Traces(1).Data(vbVariant, VsaTrcDataX, True)

Waiting For Averaged or Single Sweep Measurement Completion

The Do loop in the following macro pauses execution until the current averaged or single sweep measurement is finished. Note the use of the special functions VsaSleep and VsaDoEvents—for details about these, see Special Functions and Constants. For details about the status register and vsaStatusBitMeasDone, see Status Object in the COM API online help.

wait for measdone, but don't bother it too often

dim vTime

dim bMeasDone

vTime = Now

Do

   VsaSleep 100

   VsaDoEvents

   bMeasDone = (Measurement.Status.Value And vsaStatusBitMeasDone)<>0

exit after 5 seconds

Loop Until bMeasDone Or DateDiff("s", vTime, Now) > 5

Looping and Branching Macros

VBScript offers a number of constructs for program control, such as:

•	Subroutines and Calls

•	Do/Loop

•	For/Next

•	If/Then/Else

•	Select Case/End Case

•	While/Wend

For information about looping and branching, see the VBScript Quick Reference topic.

See also

About Macros

Sample Macros

Creating a Macro

Importing and Exporting Macros

VBScript Quick Reference


Sample Macros

This topic contains a selection of sample macros that demonstrate many common operations. You can use copy and paste to copy any of the code in this topic into your macro. Simply select the code and press Ctrl-C to copy the code to the Windows clipboard. Then place your cursor in your macro and press Ctrl-V to paste the code into your macro.

Toggle Macro

The following macro toggles the frequency counter if the marker is on:

Sub Main

Dim mkr

Set mkr = Display.Traces.ActiveTrace.Marker

If mkr.Visible Then

mkr.FreqCount = Not mkr.FreqCount

End If

End Sub

MATLAB Macro

The following macro saves a trace to a .MAT file, starts MATLAB, plots the Y data, and displays the variables in the .MAT file.

Option Explicit

Sub Main

Dim ml

Dim sRes

Display.Traces.ActiveTrace.SaveFile "C:\Temp\trace_save.mat", "mat", True

Set ml = CreateObject("Matlab.Application")

'Load .MAT file into MATLAB

sRes = ml.Execute("s=load('C:\Temp\trace_save.mat')")

'Plot data...

'Check if vector is complex or not and plot magnitude if it is.

sRes = ml.Execute("bReal = isreal(s.Y)")

sRes = ml.Execute("disp(bReal)")

If CLng(sRes) <> 0 Then

sRes = ml.Execute("plot(s.Y)")

Else

sRes = ml.Execute("plot(abs(double(s.Y)))")

End If

Display the structure read from the .MAT file

sRes = ml.Execute("disp(s)")

sRes = Replace(sRes," ","")	Get rid of extra spaces

VsaMsgBox sRes

End Sub

MER Macro

The following macro calculates and displays the MER (Message Error Rate), or SNR (signal-to-noise ratio).

Option Explicit

dim a,b

Sub Main

a = Display.Traces(4).RawDataDemodInfo(vsaTrcDemInfoSigToNoise)

b=-10*Log10(a)

VsaMsgBox b & " dB",,"MER"

End Sub

Function Log10(X)

Log10 = Log(X) / Log(10)

End Function

See also

Useful Macro Operations


TableVals (Sample Macro)

The "TableVals" macro has been provided to give you an easy method for getting the Error Summary Table data names and index numbers that are used in conjunction with the COM API RawDataValuesNames, RawDataValue(iIdx) and RawDataValueUnit(iIdx) Trace Object properties .

The TableVals macro output provides a list of the available Error Summary Table data results for the active (selected) trace display.  The output includes the data names, values, units and corresponding parameter index numbers (discussed below).

This macro also demonstrates how to programmatically read Error Summary data results from the Error Summary table using these COM API Trace Object properties; the RawDataValue(iIdx) property, the RawDataValueNames property and the RawDataValueUnit(iIdx)  property (see TableVals macro sample code below).

Note:

Available Demodulation formats, Tables and Data Names that can be used with this macro are not fixed and will change. This macro will identify the currently available Error Summary Tables and corresponding data.

Using the RawDataValue(iIdx), the RawDataValueNames and the RawDataValueUnit(iIdx) properties

It requires the RawDataValuesNames, RawDataValue(iIdx) and RawDataValueUnit(iIdx) properties to completely describe an Error Summary data result; 1) RawDataValuesNames provides the name of the measured parameter, 2) RawDataValue(iIdx) provides the measured value and 3) RawDataValueUnit(iIdx) provides the measurement units.

The RawDataValueNames returns an array containing a list of the available Error Summary Table data names for the selected active display.  This list is then used to assign unique index numbers that are used to specify the corresponding RawDataValue(iIdx) and RawDataValueUnit(iIdx) parameters.

Running the "TableVals" Macro

Its recommended that you use the "TableVals" macro to get a listing of the Error Summary data results. The macro will show the data results for the selected active Error Summary Table display.

Runing the macro:

1.	Make the desired Error Summary Table the active display

Click on the display

2.	Run the TableVals Macro

Click Utilities > Macros..,

Select "TableVals",

Click Run

TableVals macro is not available for all demodulation formats. It currently is available for these demodulation formats: 1xEV-DO, TD-SCDMA and WLAN_DSSS 802.11b/g.

Note:

Available Demodulation formats, Tables and Data Names that can be used with this macro are not fixed and will change. This macro will identify the currently available Error Summary Tables and the corresponding data results.  Use this macro to get the currently available Error Summary data results that can be used with these COM API Trace Object properties.

Example TableVals macro output

Back To Top

TableVals Macro Code

This macro operates on (provides data for) the active trace.

'-----------------------------------------------------------------------------------------------------------

' This macro demonstrates how to programmatically read values from

' symbol/summary tables for the newer demodulation formats.

'    Available                        Not available

'   ------------                    -------------------

'    TD-SCDMA                         Digital Demod

'    1x-EV-DO                         WCDMA(3GPP)

'    WLAN-DSS/CCK/PBCC                cdma2000

'                                      OFDM

' Note: Available Demods, Tables and Data Names are not fixed and

'       will change. This macro will identify the currently

'       available Error Summary Tables and data names.

'

Option Explicit

Sub Main

dim names	' array of value names

dim trc	' handle to trace obj

dim i

set trc = Display.Traces.ActiveTrace

on error resume next

' get the array of table value names

names = trc.RawDataValueNames

if err.number <> 0 then

' this is not a symbol table or this macro does not

' support the current demod type ...

VsaMsgBox "Not valid for this trace"

exit sub

end if

' the output is broken into 2 pages if the number of table

' values is greater than 25

i = LBound(names)

if UBound(names) < 25 then

OutputPage LBound(names), UBound(names), trc, names, false

else

OutputPage LBound(names), 25, trc, names, true

OutputPage 26, UBound(names), trc, names, false

end if

End Sub

Sub OutputPage(start, stp, trc, names, cont)

dim i

dim output

' for each value, print the value index, value name, value and

' value unit string

i = start

while i <= stp

output = output & i & "  "

output = output & names(i) & " = "

output = output & trc.RawDataValue(i)

output = output & " " & trc.RawDataValueUnit(i)

output = output & vbCrLf

i = i + 1

wend

' this is used when there will be more pages in the output

if cont then

output = output & "<continued>" & vbCrLf

end if

VsaMsgBox output

End Sub

'-----------------------------------------------------------------------------------------------------------

Back To Top

See also

RawDataValuesNames property

RawDataValue(iIdx)

RawDataValueUnit(iIdx)

Sample Macros

Useful Macro Operations


How To Use This Help File

To do this...	Click...
Display or hide the navigation pane (Contents, Index, and Search tabs)...
Display the documentation roadmap...
Browse through the online topics...
View the Table of Contents…
Display the online help index...
Search for a word or phrase...
Display a history of topics that you’ve visited…
To print a single topic...
To print an entire Book…	(in the Table of Contents)
To change the displayed font size…


Acknowledgements

The following products are mentioned in one or more places in the Agilent 89600-series documentation.

Product	Acknowledgement
Adobe® and Acrobat®	These products are trademarks of Adobe Systems Incorporated.
Microsoft®, Windows NT®, Windows®, and MS Windows®	These products are U.S. registered trademarks of Microsoft Corporation.
MS Excel, MS Word, MS Office, VBScript	These products are products of Microsoft Corporation.
MATLAB	MATLAB is a product of The MathWorks, Inc.


The Documentation Roadmap is not installed on your system.


1999-2002, Agilent Technologies


This documentation is not installed on your system.


This document was not available for inclusion in the online help. You can download the PDF from the 89600 [image] Web page .


This document was not available for inclusion in the online help. You can download the PDF from the 89600 [image] Web page .


This document was not available for inclusion in the online help. You can download the PDF from the 89600 [image] Web page .